package cn.wetcland.urban.admin.controller;

import cn.wetcland.urban.admin.dto.BrandAddDTO;
import cn.wetcland.urban.admin.dto.BrandUpdateDTO;
import cn.wetcland.urban.admin.dto.SubBrandAddDTO;
import cn.wetcland.urban.admin.service.UtCarTemplateService;
import cn.wetcland.urban.common.AjaxResponse;
import cn.wetcland.urban.generator.domain.UtCarTemplate;
import cn.wetcland.urban.generator.dto.BaseConditionSearchDTO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/carTemplate")
public class CarTemplateController {

    @Resource
    private UtCarTemplateService carTemplateService;

    @GetMapping("/getBrandList")
    public AjaxResponse getBrandList(BaseConditionSearchDTO searchDTO) {
        Page<UtCarTemplate> carTemplates = carTemplateService.getBrandList(searchDTO);
        return AjaxResponse.success(carTemplates);
    }

    @GetMapping("/getSerialList/{brandId}")
    public AjaxResponse getSerialList(@PathVariable Long brandId) {
        List<UtCarTemplate> carTemplates = carTemplateService.getSerialList(brandId);
        return AjaxResponse.success(carTemplates);
    }

    @DeleteMapping("/deleteCarTemplate/{id}")
    public AjaxResponse deleteCarTemplate(@PathVariable Long id) {
        carTemplateService.deleteCarTemplate(id);
        return AjaxResponse.success();
    }

    @PostMapping("/addBrand")
    public AjaxResponse addBrand(@RequestBody BrandAddDTO brandAddDTO) {
        carTemplateService.addBrand(brandAddDTO);
        return AjaxResponse.success();
    }

    @PostMapping("/addSubBrand")
    public AjaxResponse addSubBrand(@RequestBody SubBrandAddDTO subBrandAddDTO) {
        carTemplateService.addSubBrand(subBrandAddDTO);
        return AjaxResponse.success();
    }

    @PutMapping("/updateBrand")
    public AjaxResponse updateBrand(@RequestBody BrandUpdateDTO updateDTO) {
        carTemplateService.updateBrand(updateDTO);
        return AjaxResponse.success();
    }

}
